// 这里的js其实是操作popup.html产生的dom的
document.addEventListener('DOMContentLoaded', function () {


    chrome.tabs.captureVisibleTab(null, {}, function (base64) {
        /**
        * 屏幕悬挂到最上层 供截取需要的部分
        */
        sendMessageToContentScript({ type: 'get_screenshot_data', payload: base64 }, (response) => {
            console.log("response:", response);
        });
    });

    sendMessageToContentScript({ type: 'test' }, (response) => {
        console.warn("test:", response);
        console.log("popup test:", response);
    });

});

// 向content_scripts发送消息的函数
function sendMessageToContentScript(message, callback) {
    // eslint-disable-next-line no-undef
    chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
        // eslint-disable-next-line no-undef
        chrome.tabs.sendMessage(tabs[0].id, message, (response) => {
            if (callback) callback(response);
        });
    });
}

